package com.kpx.app.adapter;

import android.content.Context;

import com.amap.api.services.core.PoiItem;
import com.kpx.app.R;
import com.kpx.app.base.ComAdapter;
import com.kpx.app.base.ComViewHolder;
import com.kpx.app.utils.StringUtil;

import java.util.Collection;
import java.util.List;

/**
 * Created by chencong on 2016/12/19.
 * 定位地址选择
 */
public class ChoiceLocationAdapter extends ComAdapter<PoiItem> {
    private int currentChoosedPosition = 0;
    /**
     * 构造方法
     *
     * @param context  上下文对象
     * @param datas    数据
     * @param layoutId
     * @version 1.0
     * @createTime 2015年5月24日, 上午11:47:30
     * @updateTime 2015年5月24日, 上午11:47:30
     * @createAuthor chencong
     * @updateAuthor chencong
     * @updateInfo (此处输入修改内容, 若无修改可不写.)
     */
    public ChoiceLocationAdapter(Context context, List<PoiItem> datas, int layoutId) {
        super(context, datas, layoutId);
    }

    @Override
    public void convert(ComViewHolder holder, PoiItem poiItem, int position) {
        currentChoosedPosition = position;
        if (currentChoosedPosition == position) {
            holder.setVisibility(R.id.choosedImageView,ComViewHolder.VISIBLE);
        } else {
            holder.setVisibility(R.id.choosedImageView,ComViewHolder.INVISIBLE);
        }
        String snippet = poiItem.getSnippet();
        String provinceName = poiItem.getProvinceName();
        provinceName = StringUtil.isEmpty(provinceName) ? "" : provinceName;
        String cityName = poiItem.getCityName();
        cityName = StringUtil.isEmpty(cityName) ? "" : cityName;
        holder.setText(R.id.detailAddressView,snippet);
        holder.setText(R.id.locationView, provinceName + cityName + poiItem.getAdName());
    }

    public Collection getDatas() {
        return mDatas;
    }
}
